<template>
  <div class="user-info">
    <div class="login-panel">
      <div class="left">
        <img :src="generateImgUrl(userInfo.photoUrl)" mode="aspectFill" />
      </div>
      <div class="right">
        <div class="name">{{ userInfo.realName }}</div>
        <div class="tags">
          <div class="tag" v-if="userInfo.certificate">已实名</div>
          <div class="tag dark" v-else @click="handleFace">未实名</div>
          <div class="tag" v-if="userInfo.npcmember">人大代表</div>
        </div>
      </div>
    </div>
    <div class="list">
      <div class="list-item" @click="openDetail()">
        <div class="left">
          <i class="ali-icon iconfont icongerenziliao"></i>
        </div>
        <div class="title">个人资料</div>
        <div class="right">
          <van-icon name="arrow" color="#DDDDDD" size="18px"/>
        </div>
      </div>
      <div class="line"></div>
      <div class="list-item" @click="exit()">
        <div class="left">
          <i class="ali-icon iconfont icontuichu"></i>
        </div>
        <div class="title">退出登录</div>
        <div class="right">
          <van-icon name="arrow" color="#DDDDDD" size="18px"/>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { generateImgUrl } from '@/utils'
import { localStorage } from 'mp-storage'
import store from '@/store'

export default {
  data () {
    return {
      generateImgUrl,
    }
  },
  computed: {
    userInfo () {
      return this.$store.state.userInfo
    },
  },
  methods: {
    openDetail () {
      uni.navigateTo({
        url: '/pages/userinfo/detail',
      })
    },
    exit () {
      uni.showModal({
        title: '你确定要退出登录吗？',
        success: function (res) {
          if (res.confirm) {
            localStorage.clear()
            store.commit('SET_ISLOGIN', false)
            uni.switchTab({
              url: '/pages/home/index',
            })
          } else if (res.cancel) {
          }
        },
      })
    },
  },
}
</script>

<style lang="scss" scoped>
@import "~css/var.scss";

.user-info {

  .login-panel {
    display: flex;
    align-items: center;
    width: 100%;
    height: 104px;
    margin: 0 auto;
    background: #fff;

  .left {
    width: 70px;
    height: 70px;
    margin-left: 20px;

    img {
      width: 100%;
      height: 100%;
      border-radius: 50%;
    }
  }

  .right {
    margin-left: 20px;

    .name {
      line-height: 24px;
      font-weight: bold;
      font-size: $fz-l;
      color: #333;
    }

    .tags {
      display: flex;
      margin-top: 18px;

      .tag {
        margin-right: 8px;
        padding: 0;
        padding: 0 10px;
        border: 1px solid #e51e1e;
        border-radius: 3px;
        line-height: 21px;
        font-size: $fz-s;
        color: #fff;
        background: #e51e1e;

        &.dark {
          border: 1px solid #e51e1e;
          color: #e51e1e;
          background: #fff;
          }
        }
      }
    }
  }

  .list {
    margin-top: 10px;
    background-color: #fff;

    .list-item {
      display: flex;
      align-items: center;
      width: 100%;
      height: 44px;

      .left {
        display: flex;
        align-items: center;
        margin-left: 15px;

        img {
          width: 18px;
          height: 18px;
        }
      }

      .title {
        line-height: 44px;
        margin-left: 10px;
        font-size: $fz-m;
        color: #333333;
        font-weight: 500;
      }

      .right {
        display: flex;
        align-items: center;
        margin-left: auto;
        margin-right: 10px;

        img {
          width: 16px;
          height: 16px;
        }
      }
    }

    .line {
      margin: 0 10px;
      height: 1px;
      background: #f4f2f3;
    }
  }
}
</style>
